package cn.lanqiao.bigDate.web.controller;

import cn.lanqiao.bigDate.entity.data.DataOrderStatus;
import cn.lanqiao.bigDate.reslut.Result;
import cn.lanqiao.bigDate.web.BaseController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping(DataOrderStatusController.BASE_URL)
public class DataOrderStatusController extends BaseController{
    public static final String BASE_URL = "dataOrderStatus";

    /**
     * hanyuu
     * 页面跳转
     * @return
     */
    @RequestMapping(value = "toIndex")
    public ModelAndView toIndex(){
        ModelAndView mav = new ModelAndView();
        //指定路径
        mav.setViewName(BASE_URL + "/index");
        return mav;
    }

    /**
     * 分页查询
     * @param page
     * @param searchOrderStatusNumber
     * @return
     */
    @GetMapping(value = "findOrderStatusByPage")
    public IPage<DataOrderStatus> findOrderStatusByPage(Page<DataOrderStatus> page, String searchOrderStatusNumber){
        return dataOrderStatusService.findOrderStatusByPage(page,searchOrderStatusNumber);
    }

    /**
     * 按订单编号查询
     * @param orderNumber
     * @return
     */
    @GetMapping(value = "findOrderNumber")
    public DataOrderStatus findOrderNumber(int orderNumber){return dataOrderStatusService.findOrderNumber(orderNumber);}

    /**
     * 按订单编号删除
     * @param Numbers
     * @return
     */
    @RequestMapping(value = "deleteOrderNumber")
    public Result<String> deleteOrderNumber(String Numbers){
        Result<String> result = new Result<>();
        Boolean isSuccess = dataOrderStatusService.deleteOrderNumber(Numbers);
        if(isSuccess){
            result.setCode(200);
            result.setMsg("删除成功");
        }else{
            result.setCode(500);
            result.setMsg("删除失败");
        }
        return result;
    }

    /**
     * 添加订单信息
     * @param dataOrderStatus
     * @return
     */
    @PostMapping(value = "addOrderStatusData")
    public Result<String> addOrderStatusData(DataOrderStatus dataOrderStatus){
        Result<String> result = new Result<>();
        Boolean isSuccess = dataOrderStatusService.addOrderStatusData(dataOrderStatus);
        if(isSuccess){
            result.setCode(200);
            result.setMsg("添加成功");
        }else{
            result.setCode(500);
            result.setMsg("添加失败");
        }
        return result;
    }

    /**
     * 修改订单信息
     * @param dataOrderNumber
     * @return
     */
    @PostMapping(value = "updateOrderByNumber")
    public Result<String> updateOrderByNumber(DataOrderStatus dataOrderNumber){
        Result<String> result = new Result<>();
        Boolean isSuccess = dataOrderStatusService.updateOrderByNumber(dataOrderNumber);
        if(isSuccess){
            result.setCode(200);
            result.setMsg("修改成功");
        }else{
            result.setCode(500);
            result.setMsg("修改失败");
        }
        return result;
    }


}
